import fs from 'node:fs';
import path from 'node:path';
function moveFilesAndDirs(source, destination) {
  if (!fs.existsSync(source)) {
    console.error('Source directory does not exist.');
    return;
  }

  if (!fs.existsSync(destination)) {
    fs.mkdirSync(destination, { recursive: true });
  }

  const entries = fs.readdirSync(source);

  for (const entry of entries) {
    const sourcePath = path.join(source, entry);
    const destinationPath = path.join(destination, entry);
    if (fs.lstatSync(sourcePath).isDirectory()) {
      moveFilesAndDirs(sourcePath, destinationPath);
    } else {
      fs.renameSync(sourcePath, destinationPath);
    }
  }

  fs.rmdirSync(source);
}

export default moveFilesAndDirs;
